<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>from</title>
<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
<!--<link rel="stylesheet" type="text/css" href="metro_gray.css">-->
<link rel="stylesheet" type="text/css" href="../themes/icon.css">
<script type="text/javascript" src="../jquery.min.js"></script>
<script type="text/javascript" src="../jquery.easyui.min.js"></script>
<script type="text/javascript" src="../locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="datagrid_data1.js"></script>
<style type="text/css">
body{padding: 0px;}
.wrap_search .search_item, .wrap_search .search_item .item_text, .wrap_search .search_item .item_obj{display: inline-block;height: 28px; line-height: 28px; overflow: hidden;}
.wrap_search .search_item{width: 200px;}
.wrap_search .search_item .item_text{width: 80px; text-align: right;}
.wrap_search .search_item .item_obj{}
.wrap_search .search_item.search_between{display: inline-block; width: 400px;}
.wrap_search input,select{width: 100px;}
form th{text-align: right; font-weight: normal;}
</style>
</head>
<body>

 <div class="easyui-panel" data-options="fit:true,border:false">
    <div style="padding:0px">
    <form id="ff" method="post">
        <table cellpadding="5" width="100%">
            <tr>
                <th>表单名称:</th>
                <td><input class="easyui-textbox" type="text" name="name" data-options="required:true"></input></td>
                <th>数据表名称:</th>
                <td><input class="easyui-textbox" type="text" name="name" data-options="required:true"></input></td>
                <th>数据表名称:</th>
                <td><input class="easyui-textbox" type="text" name="name" data-options="required:true"></input></td>
            </tr>
            <tr>
                <th>主键:</th>
                <td><input class="easyui-textbox" type="text" name="email" data-options="required:true,validType:'email'"></input></td>
                <th>Email:</th>
                <td><input class="easyui-textbox" type="text" name="email" data-options="required:true,validType:'email'"></input></td>
                <th>数据表名称:</th>
                <td><input class="easyui-textbox" type="text" name="name" data-options="required:true"></input></td>
            </tr>
            <tr>
                <th>扩展js:</th>
                <td colspan="5"><input class="easyui-textbox" name="message" data-options="multiline:true" style="height:60px; width: 650px;"></input></td>
            </tr>
            <tr>
                <th>Message:</th>
                <td colspan="5"><input class="easyui-textbox" name="message" data-options="multiline:true" style="height:60px;width: 650px;"></input></td>
            </tr>
        </table>
    </form>
    <div class="easyui-tabs" data-options="border:false" style="height:500px;">
        <div title="数据">
            <table id="dg" class="easyui-datagrid" style="height:700px;" 
                    data-options="
                        fit: true,
                        border: false,
                        iconCls: 'icon-edit',
                        singleSelect: true,
                        toolbar: '#tb',
                        data: data,
                        method: 'get',
                        onClickCell: onClickCell,
                        onLoadSuccess: function(data) {
                            console.log(data);
                            setTimeout(function(){
                                for(var i = 0; i < data.rows.length; i++) {
                                    $('#dg').datagrid('beginEdit', i);
                                }
                            }, 200); 
                        }
                    ">
                <thead>
                    <tr>
                        <th data-options="field:'itemid',width:80">Item ID</th>
                        <th data-options="field:'productid',width:100,
                                formatter:function(value,row){
                                    return row.productname;
                                },
                                editor:{
                                    type:'combobox',
                                    options:{
                                        valueField:'productid',
                                        textField:'productname',
                                        method:'get',
                                        data:'optionData',
                                        required:true
                                    }
                                }">Product</th>
                        <th data-options="field:'listprice',width:80,align:'right',editor:{type:'numberbox',options:{precision:1}}">List Price</th>
                        <th data-options="field:'unitcost',width:80,align:'right',editor:'numberbox'">Unit Cost</th>
                        <th data-options="field:'attr1',width:250,editor:'textbox'">Attribute</th>
                        <th data-options="field:'status',width:60,align:'center',editor:{type:'checkbox',options:{on:'P',off:''}}">Status</th>
                    </tr>
                </thead>
            </table>
            <div id="tb" style="height:auto">
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">Append</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()">Remove</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">Accept</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">Reject</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="getChanges()">GetChanges</a>
            </div>
            <script type="text/javascript">
        
                var editIndex = undefined;
                function endEditing(){
                    if (editIndex == undefined){return true}
                    if ($('#dg').datagrid('validateRow', editIndex)){
                        var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'});
                        var productname = $(ed.target).combobox('getText');
                        $('#dg').datagrid('getRows')[editIndex]['productname'] = productname;
                        $('#dg').datagrid('endEdit', editIndex);
                        editIndex = undefined;
                        return true;
                    } else {
                        return false;
                    }
                }
                function onClickCell(index, field){
                    $('#dg').datagrid('selectRow', index).datagrid('beginEdit', index);return;
                    if (editIndex != index){
                        if (endEditing()){
                            $('#dg').datagrid('selectRow', index)
                                    .datagrid('beginEdit', index);
                            var ed = $('#dg').datagrid('getEditor', {index:index,field:field});
                            if (ed){
                                ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                            }
                            editIndex = index;
                        } else {
                            $('#dg').datagrid('selectRow', editIndex);
                        }
                    }
                }
                function append(){
                    if (endEditing()){
                        $('#dg').datagrid('appendRow',{status:'P'});
                        editIndex = $('#dg').datagrid('getRows').length-1;
                        $('#dg').datagrid('selectRow', editIndex)
                                .datagrid('beginEdit', editIndex);
                    }
                }
                function removeit(){
                    if (editIndex == undefined){return}
                    $('#dg').datagrid('cancelEdit', editIndex)
                            .datagrid('deleteRow', editIndex);
                    editIndex = undefined;
                }
                function accept(){
                    if (endEditing()){
                        $('#dg').datagrid('acceptChanges');
                    }
                }
                function reject(){
                    $('#dg').datagrid('rejectChanges');
                    editIndex = undefined;
                }
                function getChanges(){
                    var rows = $('#dg').datagrid('getChanges');
                    alert(rows.length+' rows are changed!');
                }
            </script>
        </div>
        <div title="页面" style="padding:10px">
            <p style="font-size:14px">jQuery EasyUI framework helps you build your web pages easily.</p>
            <ul>
                <li>easyui is a collection of user-interface plugin based on jQuery.</li>
                <li>easyui provides essential functionality for building modem, interactive, javascript applications.</li>
                <li>using easyui you don't need to write many javascript code, you usually defines user-interface by writing some HTML markup.</li>
                <li>complete framework for HTML5 web page.</li>
                <li>easyui save your time and scales while developing your products.</li>
                <li>easyui is very easy but powerful.</li>
            </ul>
        </div>
    </div>
    </div>
    </div>
</div>
<script>
    function submitForm(){
        $('#ff').form('submit');
    }
    function clearForm(){
        $('#ff').form('clear');
    }
</script>   


</body>
</html>